﻿//-----------------------------------------------------------------------
// <author>Paul Long</author>
//-----------

namespace TopUserCharts
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Windows.Forms.DataVisualization.Charting;

    /// <summary>
    /// Pie chart class for drawing the pie chart image.
    /// </summary>
    public partial class PieChart : Form
    {
        /// <summary>
        /// endpointValues for single pie chart.
        /// </summary>
        private double[] endpointValues;

        /// <summary>
        /// addressValues for single pie chart.
        /// </summary>
        private string[] addressValues;

        /// <summary>
        /// endpointValues2 for double pie chart.
        /// </summary>
        private double[] endpointValues2;

        /// <summary>
        /// addressValues2 for double pie chart.
        /// </summary>
        private string[] addressValues2;

        /// <summary>
        /// Type of graph.
        /// </summary>
        private GraphType graphType;

        /// <summary>
        /// Initializes a new instance of the PieChart class.
        /// Draws a signle level pie chart
        /// </summary>
        /// <param name="inYValues">Y axis values</param>
        /// <param name="inXValues">X axis values</param>
        public PieChart(double[] inYValues, string[] inXValues)
        {
            this.endpointValues = inYValues;
            this.addressValues = inXValues;

            this.graphType = GraphType.PieSingle;

            this.InitializeComponent();
        }

        /// <summary>
        /// Initializes a new instance of the PieChart class.
        /// Draws a double level pie chart
        /// </summary>
        /// <param name="inYValues">Y axis values first chart.</param>
        /// <param name="inXValues">X axis values first chart.</param>
        /// <param name="inYValues2">Y axis values second chart.</param>
        /// <param name="inXValues2">X axis values second chart.</param>
        public PieChart(double[] inYValues, string[] inXValues, double[] inYValues2, string[] inXValues2)
        {
            this.endpointValues = inYValues;
            this.addressValues = inXValues;
            this.endpointValues2 = inYValues2;
            this.addressValues2 = inXValues2;

            this.graphType = GraphType.PieDouble;

            this.InitializeComponent();
        }

        /// <summary>
        /// Type of pie chart, double or signle
        /// </summary>
        private enum GraphType
        {
            /// <summary>
            /// Single pie chart
            /// </summary>
            PieSingle,

            /// <summary>
            /// Double pie chart.
            /// </summary>
            PieDouble
        }

        /// <summary>
        /// Initializes the graph information so it can be drawn.
        /// </summary>
        /// <param name="sender">Sender Object</param>
        /// <param name="e">Event Arguments</param>
        private void GraphForm_Load(object sender, EventArgs e)
        {
            // Populate series data
            if (this.graphType == GraphType.PieDouble)
            {
                this.MyChart.Series["Series1"]["DoughnutRadius"] = "45";
                this.MyChart.Series["Series1"].Points.DataBindXY(this.addressValues2, this.endpointValues2);
                this.MyChart.Series["Series2"].Points.DataBindXY(this.addressValues, this.endpointValues);
            }
            else
            {
                this.MyChart.Series["Series1"].Points.DataBindXY(this.addressValues, this.endpointValues);
                this.MyChart.Series["Series1"]["DoughnutRadius"] = "99";
            }
        }
    }
}
